package com.eastseeway.radioproject.database;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.eastseeway.radioproject.entities.OperationParams;
import com.eastseeway.radioproject.entities.UserInfo;

import java.util.List;

@Dao
public interface UserInfoDao {

    @Insert
    long addUser(UserInfo userInfo);

    @Insert
    void addUser(UserInfo... userInfo);

    @Delete
    void deleteUser(UserInfo userInfo);

    @Delete
    void deleteUser(UserInfo... userInfo);

    @Query("select * from userinfo where is_admin = 1")
    LiveData<UserInfo> queryAdmin();

    @Update
    void updateUser(UserInfo userInfo);

    @Query("delete from userinfo")
    void deleteAll();

    @Query("select * from userinfo order by id")
//    List<UserInfo> queryAll();
    LiveData<List<UserInfo>> queryAll();

    @Query("select * from userinfo where user_name = :username")
    LiveData<UserInfo> queryUser(String username);

//    根据user_name查询快捷保存的参数
//    @Query("select radio_params from userinfo where user_name = :username")
//    LiveData<List<OperationParams>> queryOperationParams(String username);
//
////   保存快捷键参数
//    @Query("update userinfo set radio_params = :operationParamsList where user_name = :username")
//    void insertShortcut(List<OperationParams> operationParamsList,String username);

    @Query("select * from operationparams where username = :username and hasPressure = :hasPressure order by position asc")
    LiveData<List<OperationParams>> queryOperationParams(String username,boolean hasPressure);

//    @Query("update operationparams set freq = :freq, energy = :energy,skinPressure = :skinPressure,duration = :duration,depth = :depth,isEmpty = :isEmpty  where username = :username and position = :position")
//    void updateOperationParams(String username,int position,boolean isEmpty,byte freq,int energy,short skinPressure,short duration,short depth);

    @Update
    int updateOperationParams(OperationParams operationParams);

    @Insert
    void insertOperationParams(OperationParams operationParams);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long insertOrUpdateOperationParams(OperationParams operationParams);

    @Query("delete from operationparams where username = :username")
    void deleteOperationParamsByName(String username);

    @Query("update operationparams set isEmpty = 1 where username = :username")
    void updateOperationParamsIsEmpty(String username);





















}
